package com.hetwen.search.log;

import java.io.File;
import java.io.IOException;

import android.util.Log;


public class Logger {
	
	protected boolean isLogEnabled = true; 
	protected boolean isLog2FileEnabled = false;
	private File file;
	
	private static Logger logger;
	
	public static Logger getInstance(){
		if(logger==null){
			logger = new Logger();
		}
		return logger;
	}
	
	private Logger(){
	}
	
	public void setLogEnabled(boolean isEnabled){
		this.isLogEnabled = isEnabled;
	}
	
	public void setLog2File(String path,boolean isEnabled){
		this.isLog2FileEnabled = isEnabled;
		if(isEnabled && path!=null){
			this.file = new File(path);
			if(!this.file.exists()){
				//文件不存在
				try {
					this.file.createNewFile();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			
			if(this.file.isDirectory()){
				//如果是文件夹
				this.file = new File(this.file, "log.txt");
			}
		}
	}
	
	public void i(String tag,String msg){
		if(isLogEnabled)
		{
			Log.i(tag, msg);
		}
	}
	
	public void v(String tag,String msg){
		if(isLogEnabled)
		{
			Log.v(tag, msg);
		}
		
	}
	public void d(String tag,String msg){
		if(isLogEnabled)
		{
			Log.d(tag, msg);
		}
	}
	
	public void w(String tag,String msg){
		if(isLogEnabled)
		{
			Log.w(tag, msg);
		}
	}
	
	public void e(String tag,String msg){
		if(isLogEnabled)
		{
			Log.e(tag, msg);
		}
	}
	
}
